<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1" xml:lang="en">
  <title id="hq141670">pg_stat_activity</title>
  <body>
    <p>The view <codeph>pg_stat_activity</codeph> shows one row per server process with details
      about the associated user session and query. The columns that report data on the current query
      are available unless the parameter <codeph>stats_command_string</codeph> has been turned off.
      Furthermore, these columns are only visible if the user examining the view is a superuser or
      the same as the user owning the process being reported on.</p>
    <p>The maximum length of the query text string stored in the column <codeph>query</codeph> can
      be controlled with the server configuration parameter
        <codeph>track_activity_query_size</codeph>. </p>
    <table id="hq141982">
      <title>pg_catalog.pg_stat_activity</title>
      <tgroup cols="4">
        <colspec colnum="1" colname="col1" colwidth="131pt"/>
        <colspec colnum="2" colname="col2" colwidth="86pt"/>
        <colspec colnum="3" colname="col3" colwidth="85pt"/>
        <colspec colnum="4" colname="col4" colwidth="147pt"/>
        <thead>
          <row>
            <entry colname="col1">column</entry>
            <entry colname="col2">type</entry>
            <entry colname="col3">references</entry>
            <entry colname="col4">description</entry>
          </row>
        </thead>
        <tbody>
          <row>
            <entry colname="col1"><codeph>datid</codeph></entry>
            <entry colname="col2">oid</entry>
            <entry colname="col3">pg_database.oid</entry>
            <entry colname="col4">Database OID</entry>
          </row>
          <row>
            <entry colname="col1"><codeph>datname</codeph></entry>
            <entry colname="col2">name</entry>
            <entry colname="col3"/>
            <entry colname="col4">Database name</entry>
          </row>
          <row>
            <entry><codeph>pid</codeph></entry>
            <entry>integer</entry>
            <entry/>
            <entry>Process ID of this backend</entry>
          </row>
          <row>
            <entry colname="col1"><codeph>sess_id</codeph></entry>
            <entry colname="col2">integer</entry>
            <entry colname="col3"/>
            <entry colname="col4">Session ID</entry>
          </row>
          <row>
            <entry colname="col1"><codeph>usesysid</codeph></entry>
            <entry colname="col2">oid</entry>
            <entry colname="col3">pg_authid.oid</entry>
            <entry colname="col4">OID of the user logged into this backend</entry>
          </row>
          <row>
            <entry><codeph>usename</codeph></entry>
            <entry>name</entry>
            <entry/>
            <entry>Name of the user logged into this backend</entry>
          </row>
          <row>
            <entry><codeph>application_name</codeph></entry>
            <entry>text</entry>
            <entry/>
            <entry>Name of the application that is connected to this backend</entry>
          </row>
          <row>
            <entry colname="col1"><codeph>client_addr</codeph></entry>
            <entry colname="col2">inet</entry>
            <entry colname="col3"/>
            <entry colname="col4">IP address of the client connected to this backend. If this field
              is null, it indicates either that the client is connected via a Unix socket on the
              server machine or that this is an internal process such as autovacuum.</entry>
          </row>
          <row>
            <entry><codeph>client_hostname</codeph></entry>
            <entry>text</entry>
            <entry/>
            <entry>Host name of the connected client, as reported by a reverse DNS lookup of
                <codeph>client_addr</codeph>. This field will only be non-null for IP connections,
              and only when log_hostname is enabled.</entry>
          </row>
          <row>
            <entry colname="col1"><codeph>client_port</codeph></entry>
            <entry colname="col2">integer</entry>
            <entry colname="col3"/>
            <entry colname="col4">TCP port number that the client is using for communication with
              this backend, or -1 if a Unix socket is used</entry>
          </row>
          <row>
            <entry colname="col1"><codeph>backend_start</codeph></entry>
            <entry colname="col2">timestamptz</entry>
            <entry colname="col3"/>
            <entry colname="col4">Time backend process was started</entry>
          </row>
          <row>
            <entry colname="col1"><codeph>xact_start</codeph></entry>
            <entry colname="col2">timestamptz</entry>
            <entry colname="col3"/>
            <entry colname="col4">Transaction start time</entry>
          </row>
          <row>
            <entry colname="col1"><codeph>query_start</codeph></entry>
            <entry colname="col2">timestamptz</entry>
            <entry colname="col3"/>
            <entry colname="col4">Time query began execution</entry>
          </row>
          <row>
            <entry><codeph>state_change</codeph></entry>
            <entry>timestampz</entry>
            <entry/>
            <entry>Time when the <codeph>state</codeph> was last changed</entry>
          </row>
          <row>
            <entry colname="col1"><codeph>waiting</codeph></entry>
            <entry colname="col2">boolean</entry>
            <entry colname="col3"/>
            <entry colname="col4">True if waiting on a lock, false if not waiting</entry>
          </row>
          <row>
            <entry><codeph>state</codeph></entry>
            <entry>text</entry>
            <entry/>
            <entry>Current overall state of this backend. Possible values are:<ul
                id="ul_c5x_thv_kgb">
                <li>
                  <p><codeph>active</codeph>: The backend is running a query.</p>
                </li>
                <li>
                  <p><codeph>idle</codeph>: The backend is waiting for a new client command.</p>
                </li>
                <li>
                  <p><codeph>idle in transaction</codeph>: The backend is in a transaction, but is
                    not currently running a query.</p>
                </li>
                <li>
                  <p><codeph>idle in transaction (aborted)</codeph>: This state is similar to idle
                    in transaction, except one of the statements in the transaction caused an
                    error.</p>
                </li>
                <li>
                  <p><codeph>fastpath function call</codeph>: The backend is running a fast-path
                    function.</p>
                </li>
                <li>
                  <p><codeph>disabled</codeph>: This state is reported if
                      <codeph>track_activities</codeph> is disabled in this backend.</p>
                </li>
              </ul></entry>
          </row>
          <row>
            <entry><codeph>query</codeph></entry>
            <entry>text</entry>
            <entry/>
            <entry>Text of this backend's most recent query. If <codeph>state</codeph> is active
              this field shows the currently running query. In all other states, it shows the last
              query that was run.</entry>
          </row>
          <row>
            <entry colname="col1"><codeph>waiting_reason</codeph></entry>
            <entry colname="col2">text</entry>
            <entry colname="col3"/>
            <entry colname="col4">Reason the server process is waiting. The value can be:<p>lock,
                replication, or resgroup</p></entry>
          </row>
          <row>
            <entry colname="col1"><codeph>rsgid</codeph></entry>
            <entry colname="col2">oid</entry>
            <entry colname="col3">pg_resgroup.oid</entry>
            <entry colname="col4">Resource group OID or <codeph>0</codeph>.<p>See <xref
                  href="#topic1/rsg_note" format="dita">Note</xref>.</p></entry>
          </row>
          <row>
            <entry colname="col1"><codeph>rsgname</codeph></entry>
            <entry colname="col2">text</entry>
            <entry colname="col3">pg_resgroup.rsgname</entry>
            <entry colname="col4">Resource group name or <codeph>unknown</codeph>.<p>See <xref
                  href="#topic1/rsg_note" format="dita">Note</xref>.</p></entry>
          </row>
          <row>
            <entry colname="col1"><codeph>rsgqueueduration</codeph></entry>
            <entry colname="col2">interval</entry>
            <entry colname="col3"/>
            <entry colname="col4">For a queued query, the total time the query has been
              queued.</entry>
          </row>
        </tbody>
      </tgroup>
    </table>
    <note id="rsg_note">When resource groups are enabled. Only query dispatcher (QD) processes will
      have a <codeph>rsgid</codeph> and <codeph>rsgname</codeph>. Other server processes such as a
      query executer (QE) process or session connection processes will have a <codeph>rsgid</codeph>
      value of <codeph>0</codeph> and a <codeph>rsgname</codeph> value of <codeph>unknown</codeph>.
      QE processes are managed by the same resource group as the dispatching QD process. </note>
  </body>
</topic>
